﻿Public Class ucOrgChart
	Inherits System.Web.UI.UserControl

	Public Event Alert(ByVal msg As String)
	Public Event WriteToolTip(ByVal divtag As String)

	Public ReadOnly Property FirstNod As Entity.ChartItem
		Get
			Return Me.ViewState("firstnoad" & Me.ClientID)
		End Get
	End Property

	Public Sub LoadChart(ByVal officerAppId As String)
		LoadChart(BL.Officer.GetOfficerId(officerAppId), Nothing)
	End Sub

	Public Sub LoadChart(ByVal officerId As String, ByVal officerAppId As String)
		Dim dsChart As List(Of Entity.ChartItem) = Nothing

		If Not String.IsNullOrEmpty(officerAppId) Then
			Try
				dsChart = BL.Organization.Chart(officerId, officerAppId)
			Catch ex As Exception
				RaiseEvent Alert(ex.Message)
				Exit Sub
			End Try
		Else
			Try
				dsChart = BL.Organization.Chart(officerId)
			Catch ex As Exception
				Common.LogError.AddLogException(ex)
				RaiseEvent Alert("ไ่ม่สามารถดึงข้อมูลแผนผังองค์กรได้")
				Exit Sub
			End Try
		End If

		If dsChart Is Nothing Then
			RaiseEvent Alert("ไ่ม่พบข้อมูลแผนผังองค์กรที่ท่านต้องการ")
			Exit Sub
		End If

		Dim i As Integer = 1
		Dim nod As ucNods

		If dsChart IsNot Nothing AndAlso dsChart.Count > 0 Then
			Me.ViewState("firstnoad" & Me.ClientID) = dsChart.Item(0)
		Else
			Me.ViewState("firstnoad" & Me.ClientID) = Nothing
		End If

		For Each cItem As Entity.ChartItem In dsChart

			Try
				nod = Me.FindControl("ucNods" & i.ToString)
			Catch ex As Exception
				nod = Nothing
			End Try

			If nod IsNot Nothing Then
				nod.DataSource = cItem
			End If

			i += 1

		Next
	End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

	
    End Sub

	Private Sub ucNods1_WriteToolTip(ByVal divtag As String) Handles ucNods1.WriteToolTip,
	 ucNods2.WriteToolTip,
   ucNods3.WriteToolTip,
   ucNods4.WriteToolTip,
   ucNods5.WriteToolTip,
   ucNods6.WriteToolTip,
   ucNods7.WriteToolTip,
   ucNods8.WriteToolTip,
   ucNods9.WriteToolTip,
   ucNods10.WriteToolTip,
   ucNods11.WriteToolTip,
   ucNods12.WriteToolTip,
   ucNods13.WriteToolTip,
   ucNods14.WriteToolTip,
   ucNods15.WriteToolTip,
   ucNods16.WriteToolTip,
   ucNods17.WriteToolTip,
   ucNods18.WriteToolTip,
   ucNods19.WriteToolTip,
   ucNods20.WriteToolTip,
   ucNods21.WriteToolTip,
   ucNods22.WriteToolTip,
   ucNods23.WriteToolTip,
   ucNods24.WriteToolTip,
   ucNods25.WriteToolTip,
   ucNods26.WriteToolTip,
   ucNods27.WriteToolTip,
   ucNods28.WriteToolTip,
   ucNods29.WriteToolTip,
   ucNods30.WriteToolTip,
   ucNods31.WriteToolTip,
   ucNods32.WriteToolTip,
   ucNods33.WriteToolTip,
   ucNods34.WriteToolTip,
   ucNods35.WriteToolTip,
   ucNods36.WriteToolTip,
   ucNods37.WriteToolTip,
   ucNods38.WriteToolTip,
   ucNods39.WriteToolTip,
   ucNods40.WriteToolTip,
   ucNods41.WriteToolTip,
   ucNods42.WriteToolTip,
   ucNods43.WriteToolTip,
   ucNods44.WriteToolTip,
   ucNods45.WriteToolTip,
   ucNods46.WriteToolTip,
   ucNods47.WriteToolTip,
   ucNods48.WriteToolTip,
   ucNods49.WriteToolTip,
   ucNods50.WriteToolTip,
   ucNods51.WriteToolTip,
   ucNods52.WriteToolTip,
   ucNods53.WriteToolTip,
   ucNods54.WriteToolTip,
   ucNods55.WriteToolTip,
   ucNods56.WriteToolTip,
   ucNods57.WriteToolTip,
   ucNods58.WriteToolTip,
   ucNods59.WriteToolTip,
   ucNods60.WriteToolTip,
   ucNods61.WriteToolTip,
   ucNods62.WriteToolTip,
   ucNods63.WriteToolTip

		RaiseEvent WriteToolTip(divtag)
	End Sub
End Class